//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Markup;


namespace OpenLS.UI
{
    partial class GroupResources
    {
        public GroupResources()
        {
            InitializeComponent();
        }
        void OnToggleClick(object sender, RoutedEventArgs args)
        {
            ToggleButton b = (ToggleButton)sender;
            Group group = (Group)b.TemplatedParent;
            Popup popup = (Popup)group.Template.FindName("popup", group);
            if (b.IsChecked.GetValueOrDefault() && !popup.IsOpen)
                popup.IsOpen = true;
        }
        void OnPopupClosed(object sender, EventArgs args)
        {
            Popup popup = (Popup)sender;
            Group group = (Group)popup.TemplatedParent;
            if (group != null)
            {
                ToggleButton b = (ToggleButton) group.Template.FindName("toggle", group);
                if (Mouse.DirectlyOver != b)
                    b.IsChecked = false;
            }
        }
       /* void OnLoaded (object sender, object args)
        {
#if DEBUG
            FrameworkElement element = (FrameworkElement) sender;
            ContextMenu contextMenu = new ContextMenu();
            IAddChild c = contextMenu;
            c.AddChild(new MenuItem{Header = "hello"});
            element.ContextMenu = contextMenu;
#endif
        }*/
    }
}